//index.js
//获取应用实例
var app = getApp()
var myData = require('../../utils/data')
var util = require('../../utils/util')
var req = require('../../utils/reqUtils.js')

Page({
  // 页面初始数据
  data: {
    userData:{},
    addrDate:{},
  },
  // 地址编辑
  editAddr : function(e){
    console.log(e)
    wx.navigateTo({
      url:'../edit_addr/edit_addr?addrid='+e.currentTarget.dataset.addrid
    })
  },
  onLoad: function() {
    console.log(userData.nickName + "+============")
    wx.setStorageSync("nickName", userData.nickName)
    console.log(wx.getStorageSync('nickName'))
  },
  // 获取个人信息
  getMyInfo:function(e){
    var that = this
    wx.login({
      success: function (res) {
        console.log('code:'+res.code)
       
          //发送请求
          wx.request({
              url: 'http://localhost:/GetLoginCode', //改成自己的服务器地址
              data: { 
                  code: res.code ,//上面wx.login()成功获取到的code
                  operFlag: 'getOpenid',
              },
              header: {
                  'content-type': 'application/json' //默认值
              },
              success: function (res) {
                console.log(res.data.openid)
                req.get('/GetAddress', {
                  openId : res.data.openid
                }, 1)
                .then(res => {
                  console.log(res.data)
                  that.setData({
                    addrDate: res.data
                  })
                })
              }
              
          })

          
        }
    })
    let info = e.detail.userInfo
    this.setData({
      src:info.avatarUrl,
      nickName:info.nickName,
      isLogin:true
    })
    wx.setStorageSync("nickName", info.nickName)
    // console.log(wx.getStorageSync('nickName'))
  },

})
